package team.yidong.fenda.controller;

import net.sf.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import team.yidong.fenda.entity.Hospital;
import team.yidong.fenda.entity.HospitalDepartment;
import team.yidong.fenda.service.GuahaoService;
import team.yidong.fenda.service.HospitalDepartmentService;

import javax.servlet.http.HttpSession;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * Created by xuanlong on 2018/3/21.
 */
@Controller
public class GuahaoController {
    @Autowired
    GuahaoService guahaoService;
    @Autowired
    HospitalDepartmentService hospitalDepartmentService;

    @RequestMapping("/guahao")

    public String guahao(HttpSession session, Model model) {
        Integer loginHospitalId = (Integer) session.getAttribute("loginHospitalId");
        model.addAttribute("departmentList", hospitalDepartmentService.findHospitalDepartment(loginHospitalId));
        return "guahao";
    }

    @RequestMapping("/findGuahaoMasterForSys")
    @ResponseBody
    public JSONArray fingGuahao(@RequestParam Integer departmentId, @RequestParam String guahaoDate, HttpSession session) throws ParseException {
        Integer loginHospitalId = (Integer) session.getAttribute("loginHospitalId");
        return guahaoService.findGuahaoMasterForSys(loginHospitalId, departmentId, guahaoDate);
    }

    @RequestMapping("/addGuahao")
    @ResponseBody
    public void addGuahao(@RequestParam Integer guahaoDepartment, @RequestParam String addGuahaoDate, @RequestParam String addGuahaoDateTime, @RequestParam Integer addGuahaoNum, @RequestParam Integer masterSelect) {
        guahaoService.addGuahao(guahaoDepartment, addGuahaoDate, addGuahaoDateTime, addGuahaoNum, masterSelect);
    }

    @RequestMapping("/updateGuahaoNum")
    @ResponseBody
    public void updateGuahaoNum(@RequestParam Integer guahaoId, @RequestParam Integer guahaoNum) {
        guahaoService.updateGuahaoNum(guahaoId, guahaoNum);
    }
}
